package com.project.service.impl;

import com.project.bean.CarBean;
import com.project.mapper.ICarMapper;
import com.project.service.ICarService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 汽车实现类
 */
public class ICarServiceImpl extends BaseService implements ICarService {
    @Override
    public void addCar(CarBean car) {
        SqlSession session = this.getSession();
       ICarMapper mapper =  session.getMapper(ICarMapper.class);
       mapper.addCar(car);
       session.commit();
       session.close();
    }

    @Override
    public List<CarBean> findAll() {
        SqlSession session = this.getSession();
        ICarMapper mapper =  session.getMapper(ICarMapper.class);
        List<CarBean>  carBeans = mapper.findAll();
        session.close();
        return carBeans;

    }

    @Override
    public CarBean findById(int id) {
        SqlSession session = this.getSession();
        ICarMapper mapper =  session.getMapper(ICarMapper.class);
        CarBean carBeans = mapper.findById(id);
        session.close();
        return carBeans;
    }
}
